import { NextResponse } from 'next/server';
import { importAllDataFromCsv } from '@/lib/excel-to-sqlite-importer';

export async function POST() {
  try {
    console.log("API route /api/import-custom-data called.");
    const result = await importAllDataFromCsv();
    
    if (result.success) {
      return NextResponse.json({ message: result.message });
    } else {
      return NextResponse.json({ error: result.message }, { status: 500 });
    }
  } catch (error) {
    const message = error instanceof Error ? error.message : 'An unknown error occurred.';
    console.error(`[API /import-custom-data] a fatal error occurred: ${message}`);
    return NextResponse.json({ error: message }, { status: 500 });
  }
} 